package com.robotic.route.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.robotic.common.annotation.Log;
import com.robotic.common.core.controller.BaseController;
import com.robotic.common.core.domain.AjaxResult;
import com.robotic.common.enums.BusinessType;
import com.robotic.route.domain.InspectionRecord;
import com.robotic.route.service.IInspectionRecordService;
import com.robotic.common.utils.poi.ExcelUtil;
import com.robotic.common.core.page.TableDataInfo;

/**
 * 巡检记录管理Controller
 *
 * @author tian
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/admin/record")
public class InspectionRecordController extends BaseController
{
    @Autowired
    private IInspectionRecordService inspectionRecordService;

    /**
     * 查询巡检记录管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(InspectionRecord inspectionRecord)
    {
        startPage();
        List<InspectionRecord> list = inspectionRecordService.selectInspectionRecordList(inspectionRecord);
        return getDataTable(list);
    }

    /**
     * 导出巡检记录管理列表
     */
    @Log(title = "巡检记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionRecord inspectionRecord)
    {
        List<InspectionRecord> list = inspectionRecordService.selectInspectionRecordList(inspectionRecord);
        ExcelUtil<InspectionRecord> util = new ExcelUtil<InspectionRecord>(InspectionRecord.class);
        util.exportExcel(response, list, "巡检记录管理数据");
    }

    /**
     * 获取巡检记录管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionRecordService.selectInspectionRecordById(id));
    }

    /**
     * 新增巡检记录管理
     */
    @Log(title = "巡检记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionRecord inspectionRecord)
    {
        return toAjax(inspectionRecordService.insertInspectionRecord(inspectionRecord));
    }

    /**
     * 修改巡检记录管理
     */
    @Log(title = "巡检记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionRecord inspectionRecord)
    {
        return toAjax(inspectionRecordService.updateInspectionRecord(inspectionRecord));
    }

    /**
     * 删除巡检记录管理
     */
    @Log(title = "巡检记录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionRecordService.deleteInspectionRecordByIds(ids));
    }
}
